home *** CD-ROM | disk | FTP | other *** search
- // phong_vertex.cg
- //
- // This file cannot be directly compiled through CG... it first must be
- // parsed to insert channel-specific instructions.
- //
-
- struct vert2frag
- {
- float4 hPosition : POSITION;
- float4 wPosition : TEXCOORD0;
- float3 wBinormal : TEXCOORD1;
- float4 colorTexUv : TEXCOORD2;
- float3 wTangent : TEXCOORD3;
- float4 bumpTexUv : TEXCOORD4;
- float4 specTexUv : TEXCOORD5;
- float4 transpTexUv : TEXCOORD6;
- };
-
- // define inputs from application
- struct app2vert
- {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float4 colorTexUv : TEXCOORD0;
- float4 bumpTexUv : TEXCOORD1;
- float4 specTexUv : TEXCOORD2;
- float4 tangent : TEXCOORD3;
- float4 transpTexUv : TEXCOORD4;
- };
-
- vert2frag main(app2vert IN,
- uniform float4x4 modelViewProj,
- uniform float4x4 objToWorldMatrix)
- {
- vert2frag OUT;
-
- #ifdef PROFILE_ARBVP1
- modelViewProj = glstate.matrix.mvp;
- #endif
-
- // Compute the clip-space vertex position.
- //
- OUT.hPosition = mul(modelViewProj, IN.position);
-
- // Compute the world-space vertex position.
- //
- OUT.wPosition = mul(objToWorldMatrix, IN.position);
-
- // Compute the geometric normal, expressed in world space.
- // Note: we pass in the tangent and binormal vector
- // rather than the normal. Then in the fragment program,
- // we recompute the normal using a cross-product. This ensures
- // that we'll get the correct normal even when the model matrix
- // has non-proportional scale, and it's cheaper than multiplying
- // by the inverse-transpose.
- //
- float3 oNormal = normalize(IN.normal.xyz);
- float3 oBinormal = normalize(cross(oNormal, IN.tangent.xyz));
- float3 oTangent = cross(oBinormal, oNormal);
-
- float3x3 objToWorldRotationMatrix = (float3x3)objToWorldMatrix;
-
- OUT.wTangent = normalize(mul(oTangent, transpose(objToWorldRotationMatrix)));
- OUT.wBinormal = normalize(mul(oBinormal, transpose(objToWorldRotationMatrix)));
-
- // Copy the texture coordinates.
- //
- OUT.colorTexUv = IN.colorTexUv;
- OUT.bumpTexUv = IN.bumpTexUv;
- OUT.specTexUv = IN.specTexUv;
- OUT.transpTexUv = IN.transpTexUv;
-
- return OUT;
- }
-